Java program To check given number is special two digit number or not
Java program To check given number is special two digit number or not
This program helps to check whether it is special two Digit number or not. Special Two Digit Number are number for which sum of it’s sum of it’s digits and product of it’s digits is equal to the original number.
Example:
Original Number : 29
Step 1 : Sum of two digit is 2+9 = 11
Step 2 : Product of two digit 2*9 = 18
Sum of sum of two digit and product of two digit as calculate in above steps and that will be 11+18 = 29
Calculated Number is equal to original number so we can say it is Special Two Digit Number.
Java Program for special two digit number or not
import java.util.Scanner;
class SpecialTwoDigit
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a two digit number to check if it is special or not.");
int original_No=sc.nextInt();
int d1=x/10;
int d2=x%10;
int sum_product=d1+d2+d1*d2;
if(sum_product==original_No)
System.out.println(original_No+" is a special two digit number");
else
System.out.println(original_No+" is not a special two digit number");
}
}
Comments
Post a Comment
Please do not write any spam link in the comment box.